/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.cloudfarming.client.geoviewer;

import javax.swing.Action;
import nl.cloudfarming.client.geoviewer.Layer;
import nl.cloudfarming.client.geoviewer.LayerObject;
import nl.cloudfarming.client.geoviewer.MapController;
import org.openide.nodes.AbstractNode;
import org.openide.nodes.Children;
import org.openide.util.lookup.Lookups;

/**
 *
 * @author Timon Veenstra
 */
public class LayerObjectNode extends AbstractNode {

    private final LayerObject<?> layerObject;
    private final Layer<LayerObject<?>> layer;

    public LayerObjectNode(MapController mapController, Layer<LayerObject<?>> layer, LayerObject<?> layerObject) {
        super(Children.LEAF, Lookups.fixed(mapController, layer, layerObject));
        this.layerObject = layerObject;
        this.layer = layer;

    }

    public LayerObject<?> getLayerObject(){
        return this.layerObject;
    }

    /**
     * Returns the HTML display name based on the visibility of the layer.
     *
     * @return The HTML display name of the node (layer)
     */
    @Override
    public String getHtmlDisplayName() {
        String displayName = layerObject.getTooltipText();

        return "<font color='#000000'>" + displayName + "</font>";
    }

    @Override
    public Action[] getActions(boolean context) {
        return layer.getActions();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final LayerObjectNode other = (LayerObjectNode) obj;
        if (this.layerObject != other.layerObject && (this.layerObject == null || !this.layerObject.equals(other.layerObject))) {
            return false;
        }
        if (this.layer != other.layer && (this.layer == null || !this.layer.equals(other.layer))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 23 * hash + (this.layerObject != null ? this.layerObject.hashCode() : 0);
        hash = 23 * hash + (this.layer != null ? this.layer.hashCode() : 0);
        return hash;
    }

    



//    @Override
//    protected SystemAction[] createActions() {
//
//        return new SystemAction[]{SystemAction.get(SelectInMapAction.class)};
//    }
//
//
//
//    @Override
//    public SystemAction getDefaultAction() {
//        return SystemAction.get(SelectInMapAction.class);
//    }


}
